from app.MySQLDatabase import MySQLDatabase

class operate_log_service:

    def page(pageNum, pageSize):
        db = MySQLDatabase()
        conn = db.connect()
        if conn:
            cursor = conn.cursor()
            sql = "select * from operate_log order by `id` LIMIT %s OFFSET %s"
            data = (pageSize, (int(pageNum) - 1) * pageSize)
            cursor.execute(sql, data)
            result = cursor.fetchall()
            cursor.close()
            conn.commit()
            conn.close()
            return result

    def insert(content, person,  timeStamp):
        db = MySQLDatabase()
        conn = db.connect()
        if conn:
            cursor = conn.cursor()
            sql = "INSERT INTO `operate_log` ( `content`, `person`, `timestamp`) VALUES  (%s,%s,%s)"
            cursor.execute(sql, (content, person,  timeStamp))
            conn.commit()
            cursor.close()
            conn.close()

    def selectReportData():
        db = MySQLDatabase()
        conn = db.connect()
        if conn:
            cursor = conn.cursor()
            sql = "select * from operate_log where id > (select config_value from dynamic_config where config_name = 'operate_log_upload_id')  order by `id`"
            cursor.execute(sql)
            result = cursor.fetchall()
            cursor.close()
            conn.commit()
            conn.close()
            return result